package com.dycx.user.converter;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.user.dto.ReportDTO;
import com.dycx.user.entity.ReportDO;
import com.dycx.user.vo.ReportVO;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 收藏(Report)实体转换类
 *
 * @author wuzongbing
 * @since 2024-04-17 15:51:44
 */


@Data
public class ReportConverter implements Serializable {
    public static ReportDO dtoToEntity(ReportDTO dto) {
        if (dto == null) return null;
        ReportDO entity = BeanUtil.toBean(dto, ReportDO.class);
        return entity;
    }

    public static ReportVO entityToVo(ReportDO entity) {
        if (entity == null) return null;
        ReportVO vo = BeanUtil.toBean(entity, ReportVO.class);
        vo.setBizName(BizTypeEnum.converter(vo.getBizType()));

        return vo;
    }

    public static List<ReportVO> entityToVoList(List<ReportDO> entityList) {
        List<ReportVO> voList = new ArrayList<>();
        for (ReportDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<ReportVO> entityToVoPage(Page<ReportDO> page) {

        List<ReportVO> newRecords = new ArrayList<>();

        List<ReportDO> records = page.getRecords();
        for (ReportDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<ReportVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
